package net.dgg.dggcloud.service.jrcrm.service.call;

import net.dgg.dggcloud.core.minidao.hibernate.dao.IGenericBaseCommonDao;
import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.jrcrm.dao.call.NokaDao;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:
 * @Description:  录音盒，智呼保存数据
 * @author：guowei
 * @date： 2017/11/22
 */

@Service
public class NokaService extends BaseService {


    @Resource(name = "miniDaoHiberCommonDao")
    protected IGenericBaseCommonDao repository;

    @Autowired
    private NokaDao nokaDao;

    public void msgpost(String calldate, String dst, String billsec, String disposition, String amaflags, String userfield, String outbound) {

            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            String date = sf.format(new Date());
            String[] str = date.split("-");
            String name = "call_dhh"+str[0]+str[1];
            String sqlSelect = "insert into "+name+"(src,dst,data,status,length,file,type) " +
                    "values('"+outbound+"','"+dst+"','"+calldate+"','"+disposition+"','"+billsec+"','"+userfield+"','"+amaflags+"')";
        Map map = new HashMap();
        map.put("sql",sqlSelect);

        nokaDao.insertSql(map);
    }

    public void saveZhRecord(Long userId, String calltime, String callsec, String record, String dst, String src) {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            String date = sf.format(new Date());
            String[] str = date.split("-");
            String name = "call_zh"+str[0]+str[1];

            String sqlSelect = "insert into "+name+"(src,dst,calltime,user_id,callsec,record) " +
                    "values('"+src+"','"+dst+"','"+calltime+"',"+userId+","+callsec+",'"+record+"')";

        Map map = new HashMap();
        map.put("sql",sqlSelect);

        nokaDao.insertSql(map);
    }

    public Long getWorkCallRecord(Map map){
        return nokaDao.getWorkCallRecord(map);
    }



    public List<Map> listCallListenMap(Map map){
        return nokaDao.listCallListenMap(map);
    }

    public Integer countCallListenMap(Map map){
        return nokaDao.countCallListenMap(map);
    }


    public String getCallOrgIds(Map map){
        return  nokaDao.getCallOrgIds(map);
    }

    public String getDhhOrgIds(Map map){
        return  nokaDao.getDhhOrgIds(map);
    }

    public String getZhOrgIds(Map map){
        return  nokaDao.getZhOrgIds(map);
    }
}
